var transfer_id = 0;

$(function(){
    
    $("#progressbar").progressbar({value: 37});
    
    $("#btnFind").bind("click", function(e){
        var phone = $("#inpPhone").val();
        sendRequest(phone);
    });
    
    $("#btnGive").bind("click", giveTransfer);
    
});


function showMessage($msg)
{
    $("#msgBox").html($msg);
    $("#msgBox").show();
}

function showWaiting()
{
    $("#msgBox").html('');
    $("#msgBox").hide();
    $("#btnGive").hide();
}

function sendRequest(phone)
{
    $.ajax({
        url: "p_ajax.php?act=find&lang="+lang+"&phone="+phone,
        dataType: 'json',
        success: function(data)
        {
            showMessage(data.MSG);
            if(data.STATE == "OK")
            {
                transfer_id = data.id; 
                $("#btnGive").show();
            }
            else if(data.STATE == "ALERT")
            {
                $("#btnGive").hide();
            }
        }
    });

    showMessage(ss['msg-call-to']);
    $("#btnGive").hide();
}

function giveTransfer()
{
    $.ajax({
        url: "p_ajax.php?act=give&lang="+lang+"&tid="+transfer_id,
        dataType: 'json',
        success: function(data)
        {
            showMessage(data.MSG);
            //alert(var_dump(data));
            if(data.STATE == "OK")
            {
                $("#btnGive").hide();
                $("#inpPhone").val("");
            }
            //alert(data);
        }
    });
}
